/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.lieskove301.jianghongtiao.math.statistic.distributions;

import cern.jet.random.Distributions;
import cern.jet.random.engine.MersenneTwister;
import java.util.Date;

/**
 * Date of create: May 15, 2011
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 * @version 2011.0515
 */
public class WeibullDistribution implements Distribution{

    private double alpha = 2;
    private double beta = 1;

    public WeibullDistribution() {
    }

    public String getName() {
        return "Weibull Distribution";
    }

    public String getLetter() {
        return "W";
    }

    /**
     *
     * @param float x (required)
     * @param float alpha (optional, if not present used default=2)
     * @param float beta (optional, if not present used default=1)
     * @return 1.0 - Math.exp(-1.0*Math.pow(x/alpha, beta));
     */
    public double cdf(double... attr) throws IllegalArgumentException {
        if((attr == null) || (attr.length == 0) || (attr.length > 3)){
            throw new IllegalArgumentException("invalid number of arguments");
        }
        double a = alpha;
        double b = beta;
        if(attr.length > 1){
            a = attr[1];
        }
        if(attr.length >2){
            b = attr[2];
        }
        return 1.0 - Math.exp(-1.0*Math.pow(attr[0]/b, a));
    }

    public double randomNumber() {
        return Distributions.nextWeibull(alpha, beta, new MersenneTwister(new Date()));
    }

    public double randomCdf() {
        return cdf(randomNumber());
    }



}
